<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .box {
            width: 400px;
            height: 400px;
            background-color:azure;
            margin: 100px auto;
        }

        .box .mingzi {
            text-align: center;
            font-weight: bold;
            font-size: 20px;
        }

        .box div {
            margin-top: 20px;
        }

        .box .zz {
            margin-left: 50px;
        }

        input {
            width: 300px;
            height: 30px;
            outline: none;
            border: 0;
            border-radius: 5px;
        }

        .an  input{
            margin: 0 50px;
            background-color: blue;
            color: white;
        }
        .wenzi{
            font-size: 30px;
            font-weight: 400;
            text-align: center;
        }
    </style>
</head>


<body>
    <div class="box">
        <div class="wenzi">阿里云盘</div>
        <div class="mingzi">注册新账号</div>
        <div class="zz"><input type="text" placeholder="输入用户名"></div>
        <div class="zz"><input type="password" placeholder="输入密码" name="" id=""></div>
        <div class="zz"><input type="password" placeholder="确认密码" ></div>
        <div class="an"><input type="button" value="注册"></div>
    </div>
</body>

</html>
<script src="./ajax.js"></script>
<script>
    var input = document.querySelectorAll('.box input')
    var select = document.querySelector('.box .zz select')
    input[3].onclick = function () {
        if (input[0].value && input[1].value&& input[2].value) {
           if(input[1].value== input[2].value){
            if (/^\d{4}$/.test(input[1].value)) {
                ajax('get', 'https://yantianfeng.com/api/register', {
                    username: input[0].value,
                    password: input[1].value,
                }, function (data) {
                   if(data.status==400){
                    alert('注册失败！')
                   }else{
                    alert('注册成功！')
                   }
                })
            }else{
                alert('密码不符合规则')
            }
           }else{
            alert('密码不一致')
           }
        }else{
            alert('账户或密码不能为空')
        }
    }
</script>